/*
 * XMInputPanel.java
 *
 * Created on 11. Dezember 2007, 09:26
 */

package com.google.cse.emea.universaltransformer.transformers;

import java.awt.event.ActionListener;
import static java.util.logging.Level.*;
import static com.google.cse.emea.universaltransformer.TransformLogger.*;
/**
 *
 * @author  jtrapp
 */
public class XMLInputPanel extends javax.swing.JPanel {
    private String schema = null;
    /** Creates new form XMInputPanel */
    public XMLInputPanel(ActionListener validateListener, ActionListener showSchemaListener) {
        initComponents();
        validateButton.addActionListener(validateListener);
        showSchemaButton.addActionListener(showSchemaListener);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        showSchemaButton = new javax.swing.JButton();
        validateButton = new javax.swing.JButton();

        showSchemaButton.setText("View Schema ...");
        showSchemaButton.setEnabled(false);
        showSchemaButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showSchemaButtonActionPerformed(evt);
            }
        });

        validateButton.setText("Validate");
        validateButton.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(210, Short.MAX_VALUE)
                .addComponent(validateButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(showSchemaButton))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(showSchemaButton)
                    .addComponent(validateButton))
                .addContainerGap(277, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void showSchemaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showSchemaButtonActionPerformed

    }//GEN-LAST:event_showSchemaButtonActionPerformed
    
    /**
     * 
     * @param enabled
     */
    public void updateUI(boolean enableValidate, String schemaFile){
        boolean enableSchemaButton = (schema!=null) && (schema.length()>0);
        //validateButton.setVisible(enableSchemaButton);
        //showSchemaButton.setVisible(enableSchemaButton)
        validateButton.setEnabled(enableValidate&&enableSchemaButton);
        schema= schemaFile;
        showSchemaButton.setEnabled(enableSchemaButton);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton showSchemaButton;
    private javax.swing.JButton validateButton;
    // End of variables declaration//GEN-END:variables
    
}
